﻿using System;
using System.Collections.Generic;

namespace DL.Tools.SortAlgorithmTools
{
    public static class ListExtensions
    {
        private static System.Random _random;

        public static IList<T> Shuffle<T>(this IList<T> list)
        {
            if (_random == null) _random = new Random();

            var count = list.Count;

            while (count > 1)
            {
                --count;
                var index = _random.Next(count + 1);
                (list[index], list[count]) = (list[count], list[index]);
            }
            return list;
        }


    }
}